﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using LevenBlog.Core.Entities;
using LevenBlog.Core.Utils;

namespace LevenBlog.Core.Data.Sqlite
{
    public sealed class SqliteConfig : IConfig
    {
        public void Insert(IDbProvider provider, lb_config config)
        {
            IDataParameter[] paras = null;
            string sql = SqliteHelper.Instance.CreateInsertSql(config, out paras);
            SqliteHelper.Instance.ExecuteNonQuery(provider, sql, paras);
        }

        public void Update(IDbProvider provider, lb_config config)
        {
            IDataParameter[] paras = null;
            string sql = SqliteHelper.Instance.CreateUpdateSql(config, out paras);
            SqliteHelper.Instance.ExecuteNonQuery(provider, sql, paras);
        }

        public lb_config Get(IDbProvider provider)
        {
            string sql = "select * from [lb_config] order by [id] asc limit 0,1";
            using (IDataReader dr = SqliteHelper.Instance.ExecuteDataReader(provider, sql))
            {
                return SqliteHelper.Instance.ConvertToEntity<lb_config>(dr);
            }
        }
    }
}
